<?php

/**
 * class purchaseOrderDetails
 *
 * Description for class purchaseOrderDetails
 *
 * @author:peter
*/
Zend_Loader::loadClass("BaseDBRows");
Zend_Loader::loadClass("purchaseOrderDetail");
class purchaseOrderDetails extends BaseDBRows {

	protected function setUp()
	{
		$this->_tableName = purchaseOrderDetail::_tablename;	
	}
	
	public function getPodetail($org_id=0,$poid,$customerId,$fields =array()) {
	
		Zend_Loader::loadClass("purchaseOrder");
		Zend_Loader::loadClass("QueryCreator");
		Zend_Loader::loadClass("Organism");
		Zend_Loader::loadClass("OrganizationOrganism");
		
		$query = new QueryCreator();
		
		foreach($fields as $key => $value) {
			$query->addSelect($value);
		}
		
		$query->addFrom($this->_tableName . " a ");
		$query->addJoin(" LEFT JOIN ". purchaseOrder::_tablename ." b on a.po_id = b.po_id ");
		$query->addJoin(" LEFT JOIN ". OrganizationOrganism::_tablename . " d on d.org_organism_id = a.org_organism_id ");
		$query->addJoin(" LEFT JOIN ". Organism::_tablename . " organism  on organism.organism_id =  d.organism_id" );
		$query->addWhere(" a.po_id =  ". $poid . " and b.org_id = ". $customerId );
		if($org_id) {
			$query->addWhere(" a.supplier_org_id = ". $org_id );
		}
		
		$db = DBCon::instance();
		//echo $query->createSQL();
		$result = $db->executeQuery($query->createSQL());
		$data = array();
		foreach($result as $key => $value) {
			foreach($fields as $keyx => $valuex) {
					$data[] = $value[$valuex];
			}
		}
		
		return $data;
		
	}

}


?>